import 'package:shared_preferences/shared_preferences.dart';

class SPUtil {

  static String keyShowWelcome = "key_show_welcome";

  static SPUtil spUtil;
  static SharedPreferences sp;

  static Future<SPUtil> getInstance() async {
    if(spUtil==null){
      spUtil = SPUtil();
    }
    if(sp == null){
      sp = await SharedPreferences.getInstance();
    }
    return spUtil;
  }


  void putString(String key, String value) {
    if(!checkSp()) return;
    sp.setString(key, value);
  }

  void putBool(String key, bool value) async {
    if(!checkSp()) return;
    sp.setBool(key, value);
  }

  String getString(String key) {
    if(!checkSp()) return null;
    return sp.getString(key);
  }

  bool getBool(String key) {
    if(!checkSp()) return null;
    return sp.getBool(key);
  }

  static bool checkSp() {
    return sp!=null;
  }
}
